var warn_table;
var warn_table_config = {
	"iDisplayLength" : 20,
	"processing" : true,
	"serverSide" : true,
	"paging" : true,
	"lengthChange" : false,
	"searching" : false,
	"ordering" : false,
	"info" : true,
	"autoWidth" : false,
	"scrollX" : true,
	"scrollY" : 450,
	"oLanguage" : {
		"sProcessing" : "正在加载中......",
		// "sLengthMenu" : "每页显示 _MENU_ 条记录",
		"sZeroRecords" : "对不起，查询不到相关数据！",
		"sEmptyTable" : "暂无设备数据存在！",
		"sInfo" : "当前有共 _TOTAL_ 条设备记录",
		"sInfoFiltered" : "数据表中共为 _MAX_ 条记录",
		"sSearch" : "搜索",
		"oPaginate" : {
			"sFirst" : "首页",
			"sPrevious" : "上一页",
			"sNext" : "下一页",
			"sLast" : "末页"
		}
	},
	columns : [
			{
				"data" : "record_id",
				render : function(data, type, full) {
					return '<input name=\"items\" type="checkbox" id=\"check_'
							+ data + '\" value="' + data + '"/>';
				}
			},
			{
				"data" : "record_id"
			},
			{
				"data" : "warn_type"
			},
			{
				"data" : "device_type"
			},
			{
				"data" : "device_name"
			},
			{
				"data" : "warn_name"
			},
			{
				"data" : "warn_level",
				render : function(data, type, full) {
					if (data == 0) {
						return '<div style="background-color:#CC6600;color:#fff">预警</div>';
					} else if (data == 1) {
						return '<div style="background-color:#FF6600;color:#fff">1级告警</div>';
					} else if (data == 2) {
						return '<div style="background-color:#F00000;color:#fff">2级告警</div>';
					}
				}
			}, {
				"data" : "count"
			}, {
				"data" : "is_clear",
				render : function(data, type, full) {
					if (data == 0) {
						return '<lable style="color:#F00000">未确认</lable>';
					} else if (data == 1) {
						return '<lable style="color:#339933">已确认</lable>';
					}
				}
			}, {
				"data" : "first_time",
			}, {
				"data" : "username",
				render : function(data, type, full) {
					if (data == null) {
						return '';
					} else {
						return data;
					}
				}
			}, {
				"data" : "clear_time"
			}, {
				"data" : "org_name"
			} ]
};

initTable = function() {
	var urlTmp = "/warn/loadWarnInfo";
	warn_table_config.ajax = urlTmp;
	warn_table = $('#warn_table').DataTable(warn_table_config);
}

confirmWarn = function() {
	var recordIds = "";
	$('[name=items]:checkbox:checked').each(function() {
		recordIds += $(this).val() + ",";
	});
	if (recordIds == "") {
		$('#selAlert_air').html("<strong>请选择需要确认的告警记录！</strong>");
		$('#alertModal_air').modal("toggle");
	} else {
		$("#confirmWarnModel").modal("toggle");
	}
}

confirmWarnMsg = function() {
	var recordIds = "";
	$('[name=items]:checkbox:checked').each(function() {
		recordIds += $(this).val() + ",";
	});
	$.ajax({
		url : "/warn/confirmWarn",
		data : {
			"recordIds" : recordIds
		},
		success : function(data) {
			$('#promptContent_air').hide();
			$('#confirm_btn').hide();
			$('#successAlert_air').fadeIn(2000);
			$('#confirmWarnModel').on('hide.bs.modal', function() {
				warn_table.draw();
				$('#successAlert_air').hide();
				$('#promptContent_air').show();
				$('#confirm_btn').show();
			});
		}
	});
}

queryForm = function() {
	var url = '/warn/loadWarnInfo';
	var data = {};
	var form = document.getElementById("queryForm_warn"); // $('#queryForm');
	data.warn_type = form.warn_type.value;
	data.warn_level = form.warn_level.value;
	data.begin_time = form.begin_time.value;
	data.end_time = form.end_time.value;
	data.isClear = form.is_clear.value;

	$('#queryBtn_air').attr("disabled", "true");
	$('#warn_table').dataTable().api().destroy();
	warn_table_config.ajax = {
		"url" : url,
		"data" : data
	};
	warn_table_config.fnDrawCallback = function(settings) {
		$('#queryForm_btn').removeAttr("disabled");
	};
	warn_table = $('#warn_table').dataTable(warn_table_config);

}

resetForm = function() {
	var form = document.getElementById("queryForm_warn");
	form.warn_level.value = null;
	form.warn_type.value = null;
	form.begin_time.value = null;
	form.end_time.value = null;
}
